<?php

namespace app\common\model\gaokao;

use think\Model;
use think\Cache;


class Config extends Model
{

    

    

    // 表名
    protected $name = 'gaokao_config';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text'
    ];
    
    protected static function init()
    {
        self::afterInsert(function ($row) {
            Cache::rm("gaokao_config_".$row['type']);
        });

        self::afterUpdate(function ($row) {
            Cache::rm("gaokao_config_".$row['type']);
        });
    }

    
    
    public function getTypeList()
    {
        return ['zhiyuan' => __('Type zhiyuan'), 'plane' => __('Type plane'), 'study' => __('Type study')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
